public class BlockQueue {
    private int[] items = new int[1000];
    private int tail=0;
    private int head=0;
    private int size=0;
    public void put(int value) throws InterruptedException {
        synchronized (this){
while(size==items.length){
wait();
}
            items[tail] = value;
tail++;
            if(tail==items.length){
                tail=0;
            }
            size++;
            notifyAll();
        }
    }
    public int take() throws InterruptedException {
        int ret = 0;
        synchronized (this) {
            while (size == 0) {
                wait();
            }
            ret = items[head];
            head = (head + 1) % items.length;
            size--;
            notifyAll();
        }
        return ret;
    }
}
